# All relevant packages
packages <- c("dplyr", "tidyr", "stargazer", "ggplot2",
              "patchwork", "readr", "MASS")

# Install packages not yet installed
installedPackages <- packages %in% rownames(installed.packages())
if (any(installedPackages == FALSE)) {
  install.packages(packages[!installedPackages])
}

# Load packages
invisible(lapply(packages, library, character.only = TRUE))